<template>
<div style="padding: 12px">
  <div class="opt-area-02">
    <div>
    </div>
    <div class="left-con" style="margin-top: 10px">
      <div class="input-frame" style="width: 338px">
        <DatePicker type="datetimerange" format="yyyy-MM-dd HH:mm" v-model="hsjcsj" placeholder="请选择核酸检测日期" style="width: 338px"></DatePicker>
      </div>
      <Button type="info" size="small" style="margin-top: 5px;margin-right:5px" @click="init">搜索</Button>
    </div>
  </div>
  <template>
    <Table :loading="tableLoading" :columns="columns" :data="data">
      <template slot-scope="{ row, index }" slot="jcrs">
        {{row.people_num - row.hs_num}}
      </template>
    </Table>
  </template>
</div>
</template>

<script>
import { findPeopleHsNumList } from '../../../api/z-new-grid'
import { date0str1, getDate, getDateNext } from '../../../api/customer-service'

export default {
  name: 'index',
  data () {
    return {
      hsjcsj: [
        getDate(new Date()),
        getDateNext(new Date())
      ],
      columns: [
        {
          title: '社区',
          key: 'community_name',
          align: 'center'
        },
        {
          title: '社区人数',
          key: 'people_num',
          align: 'center'
        },
        {
          title: '核酸未检测人数',
          key: 'hs_num',
          align: 'center'
        },
        {
          title: '核酸未检测人数',
          slot: 'jcrs',
          align: 'center'
        }
      ],
      data: [],
      tableLoading: false
    }
  },
  methods: {
    init () {
      let data = {}
      if ((this.hsjcsj[0] === '' || this.hsjcsj[0] === undefined || this.hsjcsj[1] === '' || this.hsjcsj[1] === undefined)) {
        this.$Notice.error({ title: '查询失败！', desc: '请选择核酸日期进行查询！' })
        return
      }
      let time = this.hsjcsj
      let time1 = date0str1(time[0])
      let time2 = date0str1(time[1])
      data.hsjcsj_begin = time1
      data.hsjcsj_end = time2
      if (data.hsjcsj_begin.substring(0, 7) !== data.hsjcsj_end.substring(0, 7)) {
        this.$Notice.error({ title: '查询失败！', desc: '核酸日期无法跨月查询！' })
        return
      }
      this.tableLoading = true
      findPeopleHsNumList(data).then(ret => {
        if (ret.data.errcode === 0) {
          this.data = ret.data.data
          this.tableLoading = false
        } else {
          this.$Notice.error({ title: '查询列表信息失败', desc: ret.data.errmsg })
        }
      })
    }
  },
  mounted () {
    this.init()
  }
}
</script>

<style scoped>
.page_style {
  margin: 20px 5px;
}
.opt-area-02 {
  display: flex;
  align-items: center;
  flex-direction: column;
  border: 1px solid #abdcff;
  background-color: #f0faff;
  padding: 8px 16px 8px 16px;
  border-radius: 4px;
  margin-bottom: 10px;
}
.opt-area-02 .left-con {
  font-size: 14px;
  width: 100%;
}

.opt-area-02 .left-con span {
  font-weight: bold;
}

.opt-area-02 .right-con input {
  width: 150px;
  margin-right: 10px;
}

.opt-area-02 .right-con .input-frame {
  width: 200px;
  margin-right: 10px;
}
.input-frame {
  width: 120px;
  margin-right: 10px;
  float: left;
}
.red-star {
  font-family: SimSun;
  color: #f00;
  margin-right: 4px;
}
</style>
